home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 12 / CU Amiga Magazine's Super CD-ROM 12 (1997)(EMAP Images)(GB)[!][issue 1997-07].iso / CUCD / Games / DestructivePoker / sources / sources.lha / rect.h < prev    next >
C/C++ Source or Header  |  1997-02-13  |  2KB  |  73 lines

  1. /*
  2.         rect.h (rectangle)
  3.  
  4.         V1.00 - 181096  Kimmo Teräväinen
  5.         -----   ------  ----------------
  6.         V0.01   181096  Started
  7.         V0.05   201096  Most methods written & tested.
  8.         V0.06   211096  cPiste & cSize are inherited from cAlkioR2
  9.                         (item R²)
  10.         V0.07   031196  cPiste -> cPoint, caKuvio -> caImage
  11.         V0.08   031196  Transfered cPoint ja cSize to point.h.
  12.         V0.10   141196  Transfered out from cImage.
  13.         V0.11   271196  BUG FIXED: Inside() & OverLap were always FALSE
  14.  
  15. */
  16. #ifndef DC1_POKER_RECTANGLE
  17. #define DC1_POKER_RECTANGLE
  18.  
  19. #include "point.h"
  20. #include "IDCMP.h"
  21.  
  22. class cRectangle {
  23. protected:
  24.   cPoint pos;
  25.   cSize  size;
  26. public:
  27.   cRectangle(int a=0,int b=0,int c=0,int d=0): pos(a,b), size(c,d) {}
  28.   cRectangle(const cRectangle &rect): pos(rect.pos), size(rect.size) {}
  29.  
  30.   virtual cRectangle &operator=(const cRectangle &rect) {
  31.     pos=rect.pos;
  32.     size=rect.size;
  33.     return *this;
  34.   }
  35.  
  36.   int Left() const { return pos.X();}
  37.   int Top() const  { return pos.Y();}
  38.   int Width() const { return size.X();}
  39.   int Height() const  { return size.Y();}
  40.   int Right() const { return pos.X()+size.X()-1;}
  41.   int Bottom() const  { return pos.Y()+size.Y()-1;}
  42.  
  43.   cPoint &MoveTo(const cPoint &p) { pos=p; return pos; }
  44.   cPoint &Move(const cPoint &p) {  pos+=p; return pos; }
  45.  
  46.   int Inside(int x,int y) const {
  47.     if((pos.X()-x)>0) return FALSE;
  48.     if((pos.Y()-y)>0) return FALSE;
  49.     if((pos.X()+size.X()-x)<=0) return FALSE;
  50.     if((pos.Y()+size.Y()-y)<=0) return FALSE;
  51.     return TRUE;
  52.   }
  53.   int Inside(const cPoint &p) const { return Inside(p.X(),p.Y()); }
  54.  
  55.   int OverLap(int left,int top,int right,int bottom) const {
  56.     if((pos.X()-right)>0) return FALSE;
  57.     if((pos.Y()-bottom)>0) return FALSE;
  58.     if((pos.X()+size.X()-left)<=0) return FALSE;
  59.     if((pos.Y()+size.Y()-top)<=0) return FALSE;
  60.     return TRUE;
  61.   }
  62.   int OverLap(const cRectangle &r) const  {
  63.     return OverLap(r.Left(),r.Top(),r.Right(),r.Bottom());
  64.   }
  65. };
  66.  
  67.  
  68. class cMsgRectangle : public cRectangle , public cIDCMP {
  69. public:
  70.   cMsgRectangle(int a=0,int b=0,int c=0,int d=0): cRectangle(a,b,c,d) {}
  71. };
  72.  
  73. #endif